package app.modules.menu.application.web;

import app.modules.common.dto.web.WebIdDTO;
import app.modules.menu.business.service.MenuTemplateService;
import app.modules.menu.dto.web.template.WebMenuTemplateDTO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jasmine.framework.web.entity.WebResult;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author mh.z
 */
@Tag(name = "菜单API")
@RestController
public class MenuTemplateController {
    private MenuTemplateService menuTemplateService;

    public MenuTemplateController(MenuTemplateService menuTemplateService) {
        this.menuTemplateService = menuTemplateService;
    }

    @Operation(summary = "查询当前的菜单模板")
    @PostMapping("/api/menu/menuTemplate/getCurrentMenuTemplate")
    public ResponseEntity<WebResult<WebMenuTemplateDTO>> getCurrentMenuTemplate() {
        WebMenuTemplateDTO template = menuTemplateService.getCurrentMenuTemplate();

        return WebResult.success(template).toOkEntity();
    }

    @Operation(summary = "查询菜单模板")
    @PostMapping("/api/menu/menuTemplate/getMenuTemplateById")
    public ResponseEntity<WebResult<WebMenuTemplateDTO>> getWebMenuTemplateDtoById(
            @RequestBody WebIdDTO paramDTO) {
        Long id = paramDTO.getId();
        WebMenuTemplateDTO template = menuTemplateService.getWebMenuTemplateDtoById(id);

        return WebResult.success(template).toOkEntity();
    }

}

